﻿using System.Collections.Generic;
using System.Runtime.Remoting.Messaging;
using UnityEngine;

public abstract class IEnemy : ICharacter
{
    private EnemyFSMSystem mFSMSystem;

    public IEnemy()
    {
        MakeFSM();
    }

    public override void UnderAttack(int damage)
    {
        base.UnderAttack(damage);
        PlayEffect();
        if (mAttr.CurrentHp <= 0)
        {
            Killed();
        }
    }

    protected abstract void PlayEffect();

    public override void UpdateFSMAI(List<ICharacter> targets)
    {
        mFSMSystem.CurrState.Reasoning(targets);
        mFSMSystem.CurrState.Actioning(targets);
    }

    private void MakeFSM()
    {
        mFSMSystem = new EnemyFSMSystem();
        EnemyChaseState chaseState = new EnemyChaseState(mFSMSystem, this);
        chaseState.AddTransition(EnemyTransition.CanAttack, EnemyStateId.Attack);

        EnemyAttackState attackState = new EnemyAttackState(mFSMSystem, this);
        attackState.AddTransition(EnemyTransition.LostSoldier, EnemyStateId.Chase);

        mFSMSystem.AddState(chaseState, attackState);
    }
}